// 通过 JSON 格式的字符串创建数组
let x = [];
console.log('length: ', x.length); // Array.prototype.length
console.log('toString: ', x.toString()); // Array.prototype.toString
console.log('console.log: ', x);

console.log("-----------------------------------------------------------")

// 与其它语言中的数组不同，JS中的数组长度是可以修改的
x.length = 10;
console.log('length: ', x.length);
console.log('toString: ', x.toString());
console.log('console.log: ', x);

console.log("-----------------------------------------------------------")

x.length = 5;
console.log('length: ', x.length);
console.log('toString: ', x.toString());
console.log('console.log: ', x);

console.log("-----------------------------------------------------------")

// 随机产生5个[ 0 , 100 )内的整数并将其放入到数组中
for (let i = 0; i < x.length; i++) {
    // 产生随机数
    let r = Math.random() * 100; // [ 0 , 100 )
    // let a = Math.floor( r ); // [ 0 , 99 ]
    let a = r | 0; // 留意这里的做法
    // 将随机数放入到数组下标为i的位置
    x[i] = a;
}

console.log('length: ', x.length);
console.log('toString: ', x.toString());
console.log('console.log: ', x);